#!/bin/sh

if [ "$1" = "" ];
then
    echo -e "\033[0;31m 未输入 APP_NAME \033[0m"
    exit 1
fi

if [ "$2" = "" ];
then
    echo -e "\033[0;31m 未输入 VERSION \033[0m"
    exit 1
fi

APP_NAME=$1
VERSION=$2

echo "AppName is $APP_NAME"
echo "VERSION is $VERSION"

cd ../..
echo "当前路径: $PWD"

# maven 打包
mvn clean install -pl chat-api/${APP_NAME} -am -DskipTests

# 进入项目目录
cd chat-api/${APP_NAME}

# 删除已存在的镜像
echo "开始删除已存在的镜像"
docker rmi -f registry.cn-hangzhou.aliyuncs.com/bkhech08/${APP_NAME}:${VERSION}

echo "开始构建镜像"
# 构建镜像
# docker build -f Dockerfile -t chat/${APP_NAME}:${VERSION} .
docker build -f Dockerfile -t registry.cn-hangzhou.aliyuncs.com/bkhech08/${APP_NAME}:${VERSION} .

# 登录阿里云Docker Registry
# docker login --username=guowenmeng24@163.com --password 123456 registry.cn-hangzhou.aliyuncs.com

# 如果 tag 不同，将镜像打标签，并推送到Registry
# docker tag chat/${APP_NAME}:${VERSION} registry.cn-hangzhou.aliyuncs.com/bkhech08/${APP_NAME}:${VERSION}

# 暂时不推送至远程镜像仓库
# docker push registry.cn-hangzhou.aliyuncs.com/bkhech08/${APP_NAME}:${VERSION}


